home *** CD-ROM | disk | FTP | other *** search
-
- /*
- this is a little test of a restart scheme
- to give the user a short time to restart or
- quit the application and then aautomatically restart
- Mary Lynn Samford
- */
- static long excSave[2];
- pascal void MyRestart();
-
- main()
-
- {
- Rect r;
- long *lPtr;
- WindowPtr myWindow;
-
- EventRecord myEvent;
-
- InitGraf(&thePort);
- InitFonts();
- InitWindows();
- TEInit();
- InitDialogs(0L);
- InitCursor();
-
- /* save away the original bus & address error vectors
- (location 8 & 12 ) &
- put in our new ( address of MyRestart)
- */
-
- excSave[0] = *(long*)8;
- excSave[1] = *(long*)12;
- *(long*)8 = (long)(&MyRestart);
- *(long*)12 = (long)(&MyRestart);
-
- /* make a stupid window for this demo */
-
- myWindow = GetNewWindow(128,0l,-1L);
- SetPort(myWindow);
- SetRect(&r,60,60,200,200);
- TextBox("This is a little program to test a restart scheme. Press a 'b' \
- to cause a bus error or a 'q' to quit.",101,&r,2);
-
- while (1)
- if ( WaitNextEvent(everyEvent, &myEvent, 10L, 0L)) {
- switch ( myEvent.what) {
- case keyDown:
- switch ( myEvent.message & charCodeMask ) {
- case 'b':
- /* force a bus error */
- asm{
- move 0xfffffffe,a0
- jmp (a0)
- }
- case 'q':
- *(long*)8= excSave[0];
- *(long*)12 = excSave[1];
- ExitToShell(); /* crude & rude */
- }
- break;
- case app4Evt: /* multi-finder event */
- if (BitAnd(myEvent.message,1)) { /* activate */
- excSave[0] = *(long*)8;
- excSave[1] = *(long*)12;
- *(long*)8 = (long)(&MyRestart);
- *(long*)12 = (long)(&MyRestart);
- }
- else { /* deactivate */
- *(long*)8= excSave[0];
- *(long*)12 = excSave[1];
- }
- break;
- case updateEvt:
- myWindow = (WindowPtr) myEvent.message;
- BeginUpdate(myWindow);
- SetRect(&r,60,60,200,200);
- TextBox("This is a little program to test a restart scheme. Press a 'b' \
- to cause a bus error or a 'q' to quit.",101,&r,2);
-
- EndUpdate(myWindow);
- break;
-
- }
- }
- }
-
- CatPStr(to, from)
- char *to,*from;
- {
- int i;
-
- for(i = 1; i <= from[0]; i++) {
- to[to[0]+i] = from[i];
- }
- to[0] += i-1;
- }
-
- #define MINCOUNT 1
-
-
- pascal void MyRestart()
- {
- DialogPtr dp,theDialog;
- long finalTC;
- EventRecord myEvent;
- int item,type,min=0,sec=0;
- char time_string[100],tempstr[20];
- Handle itemHandle;
- Rect r;
- DateTimeRec date;
-
-
- finalTC = TickCount() + (60*60*MINCOUNT); /* MINCOUNT minutes in the future */
- dp = GetNewDialog (10000,0L,-1L);
- if ( dp == (DialogPtr)0) /* no Dialog ? Quit */
- asm{
- move.l ROMBase,A0
- jmp 0x0a(A0)
- }
-
- GetDItem (dp, 4 ,&type, &itemHandle,&r);
- if ( itemHandle == (Handle)0) /* no item ? Quit */
- asm{
- move.l ROMBase,A0
- jmp 0x0a(A0)
- }
- ShowWindow(dp);
- *(long*)8= excSave[0]; /* restore original error handler */
- *(long*)12 = excSave[1]; /* restore original error handler */
- while(TickCount() < finalTC ) {
- Secs2Date ((finalTC-TickCount())/60,&date);
- if (date.minute != min || date.second != sec) {
- min = date.minute;
- sec = date.second;
- NumToString (date.minute, time_string);
- CatPStr(time_string,"\P Minutes ");
- NumToString (date.second, tempstr);
- CatPStr(time_string,tempstr);
- CatPStr(time_string,"\P Seconds ");
- SetIText (itemHandle,time_string);
- }
- WaitNextEvent(everyEvent, &myEvent, 10L, 0L);
- if (IsDialogEvent (&myEvent)){
- if (DialogSelect (&myEvent, &theDialog, &item) && theDialog == dp) {
- switch (item) {
- case 1:
- asm{
- move.l ROMBase,A0
- jmp 0x0a(A0)
- }
- case 2:
- ExitToShell();
- }
- }
- }
- }
- asm{
- move.l ROMBase,A0
- jmp 0x0a(A0)
- }
- }
-
-